Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reloader should survive SyntaxError #994

Merged
merged 4 commits into from
Mar 18, 2015
Merged

reloader should survive SyntaxError #994

merged 4 commits into from
Mar 18, 2015

Conversation

wong2
Copy link
Contributor

@wong2 wong2 commented Mar 11, 2015

This implements the feature requested in issue #964.

When there is SyntaxError raised while importing the app, provides a fallback app to display those errors instead of completely exit gunicorn.

@wong2
Copy link
Contributor Author

wong2 commented Mar 12, 2015

@benoitc plz review

@berkerpeksag
Copy link
Collaborator

Couldn't this be handled in https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/base.py#L89 or even in the Reloader class?

("Content-Type", "text/plain"),
("Content-Length", str(len(msg)))
])
return iter([msg])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to add iter() here? If I remember correctly, [msg] is enough in the WSGI spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I copied it from the example on http://gunicorn.org/ , and you're right, [msg] is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berkerpeksag I've removed the iter() here

@wong2
Copy link
Contributor Author

wong2 commented Mar 12, 2015

@berkerpeksag I don't think this can be handled in Reloader or reloader callback, since the SyntaxError is happened when the new worker is starting, while Reloader or reloader callback are in charge of terminating the old worker.

@tilgovi
Copy link
Collaborator

tilgovi commented Mar 15, 2015

This looks pretty good to me.

@wong2
Copy link
Contributor Author

wong2 commented Mar 16, 2015

@tilgovi what else should I do before this can be merged?

@tilgovi
Copy link
Collaborator

tilgovi commented Mar 16, 2015

I think it seems fine, I just want to give others a chance to look at it.

@benoitc
Copy link
Owner

benoitc commented Mar 16, 2015

The patch works for me. But I would do the following changes:

  • only display the traceback in debug mode so people using the reloader for another purpose won't have it displayed
  • make the error template configurable related to Support for custom error pages #993

Thoughts?

@berkerpeksag
Copy link
Collaborator

Perhaps it would be good to make the try-except logic a method. This way, people can customize make_fail_app etc.

try:
self.wsgi = self.app.wsgi()
except SyntaxError as e:
if not self.reloader:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use self.cfg.reload

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

On Mon, Mar 16, 2015, 16:26 Berker Peksag notifications@github.com wrote:

In gunicorn/workers/base.py
#994 (comment):

@@ -116,7 +117,19 @@ def changed(fname):

     self.init_signals()
  •    self.wsgi = self.app.wsgi()
    
  •    try:
    
  •        self.wsgi = self.app.wsgi()
    
  •    except SyntaxError as e:
    
  •        if not self.reloader:
    

I'd use self.cfg.reload


Reply to this email directly or view it on GitHub
https://github.com/benoitc/gunicorn/pull/994/files#r26533913.

@wong2
Copy link
Contributor Author

wong2 commented Mar 18, 2015

@benoitc is there still a debug mode in gunicorn? I can't find it in the doc

@benoitc
Copy link
Owner

benoitc commented Mar 18, 2015

@wong2 no only debug log level (which provides the same informations) and spew setting.

@wong2
Copy link
Contributor Author

wong2 commented Mar 18, 2015

I've moved the try-catch codes to a new method load_wsgi so it's more customizable

@tilgovi
Copy link
Collaborator

tilgovi commented Mar 18, 2015

Looks great.

benoitc added a commit that referenced this pull request Mar 18, 2015
reloader should survive SyntaxError
@benoitc benoitc merged commit 83be046 into benoitc:master Mar 18, 2015
@berkerpeksag
Copy link
Collaborator

Thanks @wong2 :)

@georgexsh
Copy link
Contributor

🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants